<template>
	<view>
		<span v-show="mainflag">
			<!-- <no-info v-show="!showflag"></no-info> -->
			<div v-show="!showflag" class="flex-center flex-column" style="height: 800rpx;">
				<image src="/static/erro/nodata.png" style="width: 200rpx;height: 200rpx;"></image>
				<text class="font-color-999">暂无工单记录...下拉刷新</text>
			</div>
			<span v-show="showflag" class="content">
				<!-- 纵向排列 -->

				<!-- <uni-steps  :options="options" direction="column" :active="options.length"></uni-steps> -->
				<view v-for="(content,key) in options" :key="key" @click="toDetails(content.id,content.type)" class="border-bottom items-content-box flex-row align-items-center flex-space-between">
					<!-- <view class="item-img ">
						<image :src="content.file[0].file" class="my-img "></image>
					</view> -->
					<view class="item-content flex-column">
						<view class="company flex-row font-14px flex-space-between">
							<text class="serial lin-hid">工单类型：{{content.type}}</text>
							<text class="details">查看详情</text>
						</view>
						<view class="fuselage-number font-12px flex-space-between">
							<text class="state">机身号：{{content.eqnumber}}</text>
						</view>
						<view class="cretedate font-10px flex-space-between">
							<text>
								创建日期：{{content.createTime}}
							</text>
						</view>
					</view>
				</view>
				<image class="img-box" src="../../../../static/add.png" @click="on"></image>
				<uni-pagination style="z-index: 999; position: fixed; bottom: 20rpx;width: 100%;" :current="page" title="标题文字"
				 :total="total" :pageSize="limit" @change="change"></uni-pagination>
			</span>
		</span>
	</view>
</template>

<script>
	import uniIndexedList from "@/components/uni-indexed-list/uni-indexed-list.vue"
	import uniPagination from '@/components/uni-pagination/uni-pagination.vue'
	import uniSteps from '@/components/uni-steps/uni-steps.vue'
	import {
		getWorkOderListByEquipmentId
	} from '@/api/user/index.js'
	export default {
		components: {
			uniSteps,
			uniPagination,
			uniIndexedList
		},
		data() {
			return {
				page: 1,
				limit: 7,
				total: 0,
				mainflag: false,
				//加载完毕显示的内容标志
				showflag: false,
				//设备id
				id: '',
				reportType: [{
					id: 0,
					type: '巡检'
				}, {
					id: 1,
					type: '调试'
				}, {
					id: 2,
					type: '保养'
				}, {
					id: 3,
					type: '维修'
				}, {
					id: 4,
					type: '培训'
				}, {
					id: 5,
					type: '安装'
				}, ],
				data: [],

				options: [{
					type: '巡检',
					createTime: '2018-11-11'
				}, {
					type: '调试',
					createTime: '2018-11-12'
				}, {
					type: '保养',
					createTime: '2018-11-13'
				}, {
					type: '维修',
					createTime: '2018-11-14'
				}, {
					type: '培训',
					createTime: '2018-11-14'
				}, {
					type: '安装',
					createTime: '2018-11-14'
				}, ]
			};
		},
		methods: {
			/**
			 * @param {Object} id 工单id
			 * @param {Object} typeId 工单的类型id
			 * 
			 */
				toDetails(id, typeId) {
				uni.navigateTo({
					url: "/pages/views/engineer/WorkStatementDetails/WorkStatementDetails?id=" + id + "&typeId=" + typeId
				})
			},
			on() {
				// 允许从相机和相册扫码
				let that = this
				uni.scanCode({
					success: function(res) {
						let id = res.result.split('=')[1]
						if (id == that.id) {
							uni.navigateTo({
								url: '/pages/views/engineer/WorkStatement/WorkStatement?equipment_id=' + that.id + "&id=4&status=0"
							});
						} else {
							uni.showToast({
								icon: 'none',
								title: "该设备和当前维修单设备不匹配"
							})
						}
					}
				});
			},
			getWorkOderList() {
				getWorkOderListByEquipmentId(this.id, this.limit, this.page).then((res) => {
					console.log(res)
					if (res.result.data.length > 0) {
						this.total = res.result.count
						this.options = res.result.data
						this.options.forEach((c, index, arr) => {
							arr[index].type = this.reportType[arr[index].type].type
						})
						console.log(this.options)
						//请求成功说明有数据显示工单类型
						uni.hideLoading()
						this.mainflag = true
						this.showflag = true
					} else {
						uni.hideLoading()
						this.mainflag = true
						this.showflag = false
					}
				})
			},
			/**
			 * 分页上一页下一页事件
			 * 
			 */
			change(type) {
				this.page = type.current
				this.getWorkOderList()
				console.log("limit" + this.limit)
				console.log("page" + this.page)

			}

		},
		onShow() {
			/**
			 * 检验当前是否已经登录
			 */
			let curRoute = this.$mp.page.route;
			this.$intercept.permission(curRoute)
		},
		onLoad(op) {
			uni.startPullDownRefresh()
			this.id = op.id
			this.getWorkOderList()

		},
		onPullDownRefresh() {
			this.getWorkOderList()
			setTimeout(function() {
				uni.stopPullDownRefresh();
			}, 1000);
		}


	}
</script>

<style lang="scss" scoped>
	.content {
		height: 100%;

		.img-box {
			position: fixed;
			width: 130rpx;
			height: 130rpx;
			bottom: 130rpx;
			right: 30rpx;
		}

		.items-content-box {
			margin: 0 auto;
			background-color: #FFFFFF;
			width: 93%;
			color: #1AAD19;
			.item-content {
				height: 140rpx;
				width: 100%;
			}
			.details{
				color: #1AAD19;
			}
			.company {
				height: 37.66%;
				line-height: 52.7rpx;
			}
			
		}

		
	}
</style>
